package data.join.com.carrecord;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import data.join.com.R;
import data.join.com.carapi.ApiPref;
import data.join.com.carapi.PhotoResult;
import data.join.com.media.AppUpdateThread;
import data.join.com.utils.MyLog;

public class MainActivity extends AppCompatActivity {

    Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //startUploadFile();

        String version = AppUpdateThread.getVersionName(this);
        MyLog.D("MainActivity version="+version);
    }

    @Override
    protected void onResume() {
        super.onResume();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                finish();
            }
        },3000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    public void checkUpdate(View view){
        //ApiPref.getInstance(this).startUpdate("/sdcard/app.apk");
        //UploadLogThread.getInstance(this).wakeUp();
        //QiniuApi.checkUploadParamEmpty(null,null);
        new Thread(){
            @Override
            public void run() {
                long start = System.currentTimeMillis();
                MyLog.D("checkUpdate click 3");
//                VideoBean videoBean = VideoDBPref.getInstance().getLastVideo();
//                int startTime = (int) (videoBean.getStartTime()/1000L);
//                ApiPref.getInstance(MainActivity.this).takeVideo(0,startTime,startTime+10);


                PhotoResult photoResult =  ApiPref.getInstance(MainActivity.this).takePhoto();
                if(photoResult == null){
                    MyLog.D("checkUpdate takePhoto fail,photoResult is NULL");
                }else {
                    MyLog.D("checkUpdate takePhoto photoResult.isAvail()=" + photoResult.isAvail()+",spend="+(System.currentTimeMillis()-start)+"ms");
                }
            }
        }.start();

    }
}
